package com.ph.util;

import java.util.Enumeration;
import java.util.Iterator;
import java.util.Locale;
import java.util.ResourceBundle;

public class PropertiesUtil {
	private static final String PROPERTIES_FILE_NAME = "function";

	public static ResourceBundle getResourceBundle(String fileName) {
		Locale locale = Locale.getDefault();
		return ResourceBundle.getBundle(fileName, locale);
	}

	public static String getPropertyValue(String keyWord) {
		return getResourceBundle(PROPERTIES_FILE_NAME).getString(keyWord);
	}

	public static boolean isExisted(String value) {
		boolean isExisted = false;
		Iterator itor = iterator(getResourceBundle(PROPERTIES_FILE_NAME)
				.getKeys());
		while (itor.hasNext()) {
			if(value.equalsIgnoreCase((String)itor.next())){
				isExisted = true;
				break;
			}
		}
		
		return isExisted;
	}

	public static Iterator iterator(final Enumeration e) {
		return new Iterator() {
			public boolean hasNext() {
				return e.hasMoreElements();
			}

			public Object next() {
				return e.nextElement();
			}

			public void remove() {
				throw new UnsupportedOperationException();
			}
		};
	}

	public static void main(String arg[]) {
//		System.out.println(isExisted("test"));
		
//		System.out.println(isExisted("fuck"));
	}
}
